package ua.yandex.skipass;

/**
 * Система управления
 *
 * @author WslF
 */
import ua.yandex.collections.MyArrayList;

public class SkiPassSystem {

    public static final SkiPassSystem INSTANCE = new SkiPassSystem();
    private final MyArrayList lockedPasses;
    private int numberOfQueries;
    private int numberOfUnsuccessfulQueries;

    private SkiPassSystem() {
        lockedPasses = new MyArrayList();
        numberOfQueries = 0;
        numberOfUnsuccessfulQueries = 0;
    }

    public Pass makeNewPass(TypeOfPasses typeOfPasses) {
        return Pass.createNewPass(typeOfPasses);
    }

    private boolean isLockedPass(Pass pass) {
        return lockedPasses.indexOf(pass) == -1;
    }

    public void lockedPass(Pass pass) {
        lockedPasses.add(pass);
    }

    public boolean couldUse(Pass pass) {
        numberOfQueries++;
        if (!pass.couldUse() || isLockedPass(pass)) {
            numberOfUnsuccessfulQueries++;
            return false;
        }
        return true;
    }

    public int getNumberOfPasses() {
        return Pass.getNumberOfPasses();
    }

    public int getNumberOfQueries() {
        return numberOfQueries;
    }

    public int getNumberOfUnsiccessefulQueries() {
        return numberOfUnsuccessfulQueries;
    }
}
